package com.anlu.zk.core.test;

import com.anlu.zk.core.ZooKeeperDistributedLock;
import com.anlu.zk.zksession.ZooKeeperSession;

public class OrderNumGenerater {


    private static int num=0;
    private static Object lock = new Object();


    public String getNumber(int i){
            //声明分布式锁
            ZooKeeperDistributedLock lock = ZooKeeperDistributedLock.getInstance();
            lock.acquireDistributedLock(i+"");

            num=num+1;
            System.out.println("当前订单号："+num);
            lock.unlock();
            return "当前订单号："+num;

    }




//    public String getNumber(){
//        try{
//            zooKeeperDistributedLock.acquireDistributedLock();
//            num=num+1;
//            return "当前订单号："+num;
//        }finally {
//            zooKeeperDistributedLock.unlock();
//        }
//
//
//    }





//    public String getNumber(){
//        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss");
//        String result = simpleDateFormat.format(new Date())+"-"+ ++num;
//        return result;
//    }
}
